package com.vitamo.client;





import java.util.List;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.sun.java.swing.plaf.windows.resources.windows;
import com.vitamo.Beans.UtilisateurB;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.MenuItemSeparator;
import com.google.gwt.view.client.ListDataProvider;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class SG_VITAMO implements EntryPoint {
	
	public final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
	public DialogBox d;
	private EspaceAdmin e;
	private Hyperlink lienlogin;
	private Hyperlink lienlogout;
	private AbsolutePanel absolutePanel_1; 
	public FormulaireInscription f;
	private AbsolutePanel absolutePanel_5 ;
	private DockLayoutPanel dockLayoutPanel;
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		rootPanel.setStyleName((String) null);
		rootPanel.setPixelSize(1000,720);
		dockLayoutPanel = new DockLayoutPanel(Unit.PX);
		
		
		dockLayoutPanel.setStyleName("app");
		rootPanel.add(dockLayoutPanel,200,10);
	
		dockLayoutPanel.setSize("900px", "700px");
		
		absolutePanel_1 = new AbsolutePanel();
		absolutePanel_1.setStyleName("Header");
		dockLayoutPanel.addNorth(absolutePanel_1, 151.0);
		
	
		
		lienlogin = new Hyperlink();
		lienlogin.setText("LOGIN");
		lienlogin.setStyleName("login");
		absolutePanel_1.add(lienlogin, 852, 119);
		lienlogin.setSize("48px", "19px");
		
		 lienlogout = new Hyperlink();
		 lienlogout.setText("LOGOUT");
		 lienlogout.setStyleName("h1");
		//absolutePanel_1.add(lienlogout, 850, 119);
		 
		
		
		Image image = new Image("images/logo.png");
		absolutePanel_1.add(image, 10, 27);
		image.setSize("139px", "63px");
		
		Label lblSystemDeGestion = new Label("System de Gestion VITAMO");
		lblSystemDeGestion.setStyleName("LabelGras");
		absolutePanel_1.add(lblSystemDeGestion, 306, 55);
		lblSystemDeGestion.setSize("303px", "35px");
		
		
		
		
		
		AbsolutePanel absolutePanel_2 = new AbsolutePanel();
		absolutePanel_2.setStyleName("foot");
		dockLayoutPanel.addSouth(absolutePanel_2, 71.0);
		
		 absolutePanel_5 = new AbsolutePanel();
		dockLayoutPanel.add(absolutePanel_5);
		
		MenuBar menuBar = new MenuBar(false);
		absolutePanel_5.add(menuBar, 10, 0);
		
		MenuItem mntmHome = new MenuItem("Home", false, (Command) null);
		menuBar.addItem(mntmHome);
		
		MenuItemSeparator separator = new MenuItemSeparator();
		menuBar.addSeparator(separator);
		
		MenuItem mntmNosServies = new MenuItem("Nos servies", false, (Command) null);
		menuBar.addItem(mntmNosServies);
		
		MenuItemSeparator separator_1 = new MenuItemSeparator();
		menuBar.addSeparator(separator_1);
		
		MenuItem mntmAbout = new MenuItem("About", false, (Command) null);
		menuBar.addItem(mntmAbout);
		//rootPanel.add(d);
		lienlogin.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				d.center();
				d.show();
			}
			
		});
		lienlogout.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				absolutePanel_1.remove(lienlogout);
				dockLayoutPanel.remove(e);
				dockLayoutPanel.add(absolutePanel_5);
				absolutePanel_1.add(lienlogin, 852, 119);
				
			}
			
		});
		
		AbsolutePanel absolutePanel = new AbsolutePanel();
		absolutePanel.setStyleName("pop");
		absolutePanel.setSize("310px", "196px");
		Button fermer = new Button("Close");
		fermer.setText("Fermer");
		absolutePanel.add(fermer, 255, 133);
		fermer.setSize("55px", "30px");
		
		Button connecter = new Button("Connecter");
		absolutePanel.add(connecter, 180, 133);
		connecter.setSize("69px", "30px");
		
		Label lblVeulliezEntrerVotre = new Label("Veulliez entrer votre  Nom d'utillisateur et ton mot de passe :");
		absolutePanel.add(lblVeulliezEntrerVotre, 10, 10);
		lblVeulliezEntrerVotre.setSize("300px", "24px");
		
		final TextBox username = new TextBox();
		absolutePanel.add(username, 137, 59);
		
		final PasswordTextBox pwd = new PasswordTextBox();
		absolutePanel.add(pwd, 137, 99);
		pwd.setSize("163px", "16px");
		
		Label lblNewLabel = new Label("Nom Utilasateur :");
		absolutePanel.add(lblNewLabel, 17, 59);
		
		Label lblNewLabel_1 = new Label("Mot de passe  :");
		absolutePanel.add(lblNewLabel_1, 17, 107);
		
		d= new DialogBox();
		d.setPopupPosition(100, 100);
		d.setGlassEnabled(true);
	    d.setAnimationEnabled(true);
		d.add(absolutePanel);
		
		Hyperlink formulaire = new Hyperlink("Creer Votre Compte Utilistaeur", false, "newHistoryToken");
		absolutePanel.add(formulaire, 102, 169);
		formulaire.setSize("208px", "20px");
	
		
		f=new FormulaireInscription(greetingService);
		f.setPopupPosition(100, 100);
		f.setGlassEnabled(true);
	    //f.setAnimationEnabled(true);
		formulaire.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				d.hide();
				
				f.show();
				
			}
		});
		
		fermer.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				// TODO Auto-generated method stub
				d.hide();
			}
		});
		connecter.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				
				String a=username.getText();
				String b=pwd.getText();
				greetingService.connect(a, b, new AsyncCallback<String>() {
					
					@Override
					public void onSuccess(String result) {
							if (result.equals("AD")) {
								 e=new EspaceAdmin(greetingService);
								 dockLayoutPanel.remove(absolutePanel_5);
								dockLayoutPanel.add(e);
								d.hide();
								absolutePanel_1.remove(lienlogin);
								absolutePanel_1.add(lienlogout, 850, 119);
								
							} else {
								Window.alert(result);
							}
							
					}
					
					@Override
					public void onFailure(Throwable caught) {
						
					}
				});
			}
		});
		
	}
}
